For an overview of the relationship between the user process, kernel, and the control entry point, see "Overview of Device Control".
The prototype of the entry point is
The argument values areint pfxioctl(dev_t dev, int cmd, void *arg, int mode, cred_t *crp, int *rvalp);
dev | A dev_t value from which you can extract the major and minor device numbers. |
cmd | The request value specified in the ioctl() call. |
arg | The optional argument value specified in the ioctl() call, or NULL if none was specified. |
mode | Flag bits specifying the open() mode, as associated with the file descriptor passed to the ioctl() system function. |
crp | A cred_t object--an opaque structure for use in authentication, describing the process that is in-context. Standard access privileges to the special device file have already been verified. |
*rvalp | The integer result to be returned to the user process. |
It is up to the device driver to interpret the cmd and arg values in the light of the mode and other arguments. When the arg value is a pointer to data in the process address space, the driver uses the copyin() kernel function to copy the data into kernel space, and the copyout() function to return updated values. (See the copyin(D3) and copyout(D3) reference pages, and also "Transferring Data".)